
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author TQNINH
 */

public class BloodReservoirTest extends BloodReservoir {
    private int aVolume;
    
    public void input() {
        int theUnit;
        int theAVolume;
        double theCost;
        Scanner src = new Scanner(System.in);        
        
        System.out.print("Enter total volume: ");
        theUnit = src.nextInt();
        setUnit(theUnit);
        
        System.out.print("Enter additional volume: ");
        theAVolume = src.nextInt();
        aVolume = theAVolume;
        
        System.out.print("Enter the price per unit: ");
        theCost = src.nextDouble();
        setCost(theCost);
    }
    
    public void sell() {
        if((getUnit() - aVolume) <= 30) {
            System.out.println("Error -> Units in counter is insufficient");
        } else {
            int n;
            Scanner src = new Scanner(System.in);
            while(true) {
                try{
                    System.out.print("How many amount of blood pints you want to book: ");
                    n = src.nextInt();
                    if(n <= 30){
                        throw new IllegalArgumentException("Error -> Must be > 30 unit");
                    } else if (n > (getUnit() - aVolume)) {
                        throw new IllegalArgumentException("Error -> Units in counter is insufficient");
                    }
                    break;
                } catch(NumberFormatException e) {
                    System.out.println("Error -> Number format!");
                } catch(IllegalArgumentException e) {
                    System.out.println(e);
                }
            }
            setSoldUnit(n);
        }
    }
    
    public void report() {
        System.out.println("Units in stock: " + getUnit());
        System.out.println("Additional units: " + this.aVolume);
        System.out.println("Price per unit: " + getCost());
        System.out.println("Sold: ");
        getDetailUnitSold();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        boolean flag = false;
        BloodReservoirTest counter1 = new BloodReservoirTest();
        BloodReservoirTest counter2 = new BloodReservoirTest();
        BloodReservoirTest counter3 = new BloodReservoirTest();
        
        while(true) {
            int choice;
            Scanner src = new Scanner(System.in);
            
            System.out.println("\n-- MENU --");
            if(!flag) {
                System.out.println("1. Admin (only one)");
            }
            System.out.println("2. Customer");
            System.out.println("3. Report");
            System.out.println("4. Exit");
            System.out.print("Choice: ");
            choice = src.nextInt();
            switch (choice) {
                case 1:
                    if(!flag) {
                        System.out.println("\nCounter 1 information:");
                        counter1.input();
                        System.out.println("\nCounter 2 information:");
                        counter2.input();
                        System.out.println("\nCounter 3 information:");
                        counter3.input();
                        flag = true;
                    }
                    break;
                case 2:
                    System.out.print("\nWhat counter you want books blood? 1/2/3: ");
                    int node;
                    node = src.nextInt();
                    if(node == 1) {
                        System.out.println("Couter 1: ");
                        counter1.sell();
                    } else if (node == 2) {
                        System.out.println("Couter 2: ");
                        counter2.sell();
                    } else if (node == 3) {
                        System.out.println("Couter 3: ");
                        counter3.sell();
                    }
                    break;
                case 3:
                    System.out.println("Counter 1 information:");
                    counter1.report();
                    System.out.println("Counter 2 information:");
                    counter2.report();
                    System.out.println("Counter 3 information:");
                    counter3.report();
                    break;
                case 4:
                    System.exit(0);
                default:
                    if(!flag){
                        System.out.println("Please enter 1,2 or 3");
                    } else {
                        System.out.println("Please insert 2 or 3");
                    }
            }
        }
    }
}
